home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / langguid / chap_06 / xmpl_07.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  1.0 KB  |  42 lines  |  [TEXT/ttxt]

  1. --<<<
  2. -- Kaleida Labs, Inc.
  3. -- Field Guide to the ScriptX Language
  4. -- chapter 6, example 7
  5.  
  6. -- create a module to avoid namespace conflicts
  7. module Scratch30 uses ScriptX end
  8. in module Scratch30
  9.  
  10. -- take care of global declarations in this file
  11. global tryThisOut, i, myArrayOfIntegers
  12.  
  13.  
  14. -- examples of free method definitions
  15.  
  16. -- add a method to an existing object
  17. tryThisOut := #(1,2)
  18. method appendSum self {object tryThisOut} n m -> 
  19.     (append self (n + m); return self)
  20.  
  21. -- add a method to an existing scripted class    
  22. class MyClass () end
  23. method jellydonut self {class MyClass} name -> 
  24.     format debug "%* is not a jellydonut!\n" name @Unadorned
  25.  
  26. i := new myclass
  27. jellydonut i "cruller"
  28.  
  29. -- define a sequence, then override the append method
  30. global myArrayOfIntegers := #()
  31.  
  32. -- override the append method on myArrayOfIntegers
  33. method append self {object myArrayOfIntegers} item -> (
  34.     if (getClass item = ImmediateInteger) then (
  35.         nextMethod self item
  36.     )
  37.     else (
  38.         format debug "Not an ImmediateInteger: %*\n" item @normal
  39.         return undefined
  40.     )
  41. )
  42. -->>>